[WPF] ComboBox.Text not taking the ItemStringFormat property into account

Posted by Thomas Levesque on Stack Overflow See other posts from Stack Overflow or by Thomas Levesque
Published on 2010-05-17T08:02:59Z Indexed on 2010/05/17 9:50 UTC
Read the original article Hit count: 840

Filed under:
|
|
|

I just noticed a strange behavior which looks like a bug. Consider the following XAML :

<Page
  xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
  xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
  xmlns:sys="clr-namespace:System;assembly=mscorlib">
  <Page.Resources>
    <x:Array x:Key="data" Type="{x:Type sys:String}">
        <sys:String>Foo</sys:String>
        <sys:String>Bar</sys:String>
        <sys:String>Baz</sys:String>
    </x:Array>
  </Page.Resources>
  <StackPanel Orientation="Vertical">
      <Button>Boo</Button>
      <ComboBox Name="combo" ItemsSource="{Binding Source={StaticResource data}}" ItemStringFormat="##{0}##" />
      <TextBlock Text="{Binding Text, ElementName=combo}"/>
  </StackPanel>
</Page>

The ComboBox displays the values as "##Foo##", "##Bar##" and "##Baz##". But the TextBlock displays the selected values as "Foo", "Bar" and "Baz". So the ItemStringFormat is apparently ignored for the Text property...

Is that a bug ? If it is, is there a workaround ?
Or am I just doing something wrong ?

© Stack Overflow or respective owner

Related posts about wpf

Related posts about xaml